using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using ObjectLib;

namespace ObjectParser
{
	/// <summary>
	/// Summary description for CircleDialog.
	/// </summary>
	public class CircleDialog : System.Windows.Forms.Form
	{
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.ListView listView1;
		private System.Windows.Forms.Button butOK;
		private System.Windows.Forms.ContextMenu contextMenu1;
		private System.Windows.Forms.MenuItem mAddNew;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.MenuItem mDelete;
		public new FormParse Owner;
		public Circle[] Circles
		{get{
				Circle[] output = new Circle[listView1.Items.Count];
				for(int i=0; i<listView1.Items.Count; i++)
				{
					output[i] = (Circle)listView1.Items[i].Tag;
					output[i].Display = listView1.Items[i].Checked;
				}
				return output;
		}}
		public int ActiveInd
		{get{
			if(listView1.SelectedIndices.Count > 0)
				return listView1.SelectedIndices[0];
			 else
				return 0;
		}}
		public CircleDialog(FormParse owner, Circle[] circlesIn)
		{
			InitializeComponent();

			Owner = owner;
			for(int i=0; i<circlesIn.Length; i++)
			{
				listView1.Items.Add( new ListViewItem(circlesIn[i].ToString()) );
				listView1.Items[i].Tag = circlesIn[i];
				listView1.Items[i].Checked = circlesIn[i].Display;
			}
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.listView1 = new System.Windows.Forms.ListView();
            this.contextMenu1 = new System.Windows.Forms.ContextMenu();
            this.mAddNew = new System.Windows.Forms.MenuItem();
            this.mDelete = new System.Windows.Forms.MenuItem();
            this.butOK = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // listView1
            // 
            this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.listView1.CheckBoxes = true;
            this.listView1.ContextMenu = this.contextMenu1;
            this.listView1.Location = new System.Drawing.Point(0, 32);
            this.listView1.MultiSelect = false;
            this.listView1.Name = "listView1";
            this.listView1.Size = new System.Drawing.Size(253, 197);
            this.listView1.TabIndex = 0;
            this.listView1.UseCompatibleStateImageBehavior = false;
            this.listView1.View = System.Windows.Forms.View.List;
            // 
            // contextMenu1
            // 
            this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.mAddNew,
            this.mDelete});
            this.contextMenu1.Popup += new System.EventHandler(this.contextMenu1_Popup);
            // 
            // mAddNew
            // 
            this.mAddNew.Index = 0;
            this.mAddNew.Text = "Add New...";
            this.mAddNew.Click += new System.EventHandler(this.mAddNew_Click);
            // 
            // mDelete
            // 
            this.mDelete.Index = 1;
            this.mDelete.Text = "Delete";
            this.mDelete.Click += new System.EventHandler(this.mDelete_Click);
            // 
            // butOK
            // 
            this.butOK.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.butOK.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.butOK.Location = new System.Drawing.Point(0, 229);
            this.butOK.Name = "butOK";
            this.butOK.Size = new System.Drawing.Size(253, 24);
            this.butOK.TabIndex = 1;
            this.butOK.Text = "OK";
            this.butOK.Click += new System.EventHandler(this.butOK_Click);
            // 
            // label1
            // 
            this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.label1.Location = new System.Drawing.Point(0, 0);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(253, 32);
            this.label1.TabIndex = 2;
            this.label1.Text = "Select the active circle and check the circles to be displayed.";
            // 
            // CircleDialog
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(253, 251);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.butOK);
            this.Controls.Add(this.listView1);
            this.Name = "CircleDialog";
            this.Text = "Circles";
            this.ResumeLayout(false);

		}
		#endregion

		private void contextMenu1_Popup(object sender, System.EventArgs e)
		{
			this.mDelete.Enabled= (listView1.Items.Count>0);
		}
		private void mAddNew_Click(object sender, System.EventArgs e)
		{
			Circle circle = new Circle(new PointF(Owner.Bmp.Width/2, Owner.Bmp.Height/2), 50, true);
			listView1.Items.Add( new ListViewItem(circle.ToString() ) );
			listView1.Items[listView1.Items.Count-1].Checked = true;
			listView1.Items[listView1.Items.Count-1].Tag = circle;
		}
		private void mDelete_Click(object sender, System.EventArgs e)
		{
			if(listView1.SelectedItems.Count > 0)
				listView1.Items.Remove(listView1.SelectedItems[0]);
		}
		private void butOK_Click(object sender, System.EventArgs e)
		{
			this.DialogResult = DialogResult.OK;
			this.Close();
		}
	}
}
